home *** CD-ROM | disk | FTP | other *** search
- class SideScroller.SideScrollerManager extends Library.DispatcherBase
- {
- var mcRef;
- var oParentObject;
- var aLayers;
- var nCurrentPosition;
- var bAutoScroll;
- var nNextDepth;
- var nStageWidth;
- var nStageHeight;
- var oCamera;
- var nScrollSpeed;
- var nScrollMethod;
- var oDefaultLayerId;
- var bPaused;
- static var _oCtrl;
- static var LOOP_BUFFER = 150;
- static var SCROLL_ONE_WAY = 1;
- static var SCROLL_BOTH_SIDE = 2;
- static var ONE_WAY_CAMERA_BUFFER = 120;
- function SideScrollerManager(__mcRef, __nStageWidth, __nStageHeight, __oParentObject)
- {
- super();
- this.mcRef = __mcRef;
- this.oParentObject = __oParentObject;
- SideScroller.Ground.doClean();
- SideScroller.SideScrollerManager._oCtrl = this;
- this.aLayers = new Array();
- this.nCurrentPosition = 0;
- this.bAutoScroll = false;
- this.nNextDepth = 0;
- this.nStageWidth = __nStageWidth;
- this.nStageHeight = __nStageHeight;
- this.oCamera = new SideScroller.BasicCamera(this.nStageWidth,this.nStageHeight,this);
- this.oParentObject.doAddListener(this);
- }
- static function get Instance()
- {
- return SideScroller.SideScrollerManager._oCtrl;
- }
- function doEnterFrame()
- {
- super.doEnterFrame();
- this.doMoveLayers();
- }
- function doAddLayer(__oLayerID, __nLayerType, __nAttachMethod)
- {
- var _loc3_ = this.mcRef.createEmptyMovieClip(__oLayerID.toString() + "_" + this.nNextDepth,this.nNextDepth);
- var _loc2_ = new SideScroller.Layer(__oLayerID,_loc3_,__nLayerType,__nAttachMethod,this);
- this.aLayers.push(_loc2_);
- this.nNextDepth = this.nNextDepth + 1;
- return _loc2_;
- }
- function setScrollSpeed(__nScrollSpeed)
- {
- this.nScrollSpeed = __nScrollSpeed;
- }
- function setScrollMethod(__nScrollMethod)
- {
- this.nScrollMethod = __nScrollMethod;
- }
- function setDefaultLayer(__oLayerID)
- {
- this.oDefaultLayerId = __oLayerID;
- }
- function getLayer(__oLayerID)
- {
- var _loc3_ = undefined;
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ <= this.aLayers.length - 1)
- {
- if(this.aLayers[_loc2_].Id == __oLayerID)
- {
- _loc3_ = this.aLayers[_loc2_];
- }
- _loc2_ = _loc2_ + 1;
- }
- return _loc3_;
- }
- function getLayerFor(__mcObject)
- {
- var _loc3_ = undefined;
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ <= this.aLayers.length - 1)
- {
- if(String(__mcObject).indexOf(String(this.aLayers[_loc2_].Ref)) != -1)
- {
- _loc3_ = this.aLayers[_loc2_];
- }
- _loc2_ = _loc2_ + 1;
- }
- return _loc3_;
- }
- function doAddStaticObject(__mcObject)
- {
- var _loc2_ = this.getLayerFor(__mcObject);
- var _loc3_ = new SideScroller.StaticObject(__mcObject,_loc2_);
- }
- function doDestroy()
- {
- this.oParentObject.doRemoveListener(this);
- this.oCamera.doDestroy();
- delete this.oCamera;
- delete SideScroller.SideScrollerManager._oCtrl;
- delete this.oParentObject;
- for(var _loc3_ in this.aLayers)
- {
- this.aLayers[_loc3_].doDestroy();
- }
- super.doDestroy();
- }
- function get Active()
- {
- return !this.bPaused;
- }
- function get StageWidth()
- {
- return this.nStageWidth;
- }
- function get StageHeight()
- {
- return this.nStageHeight;
- }
- function get ScrollMethod()
- {
- return this.nScrollMethod;
- }
- function get CameraManager()
- {
- return this.oCamera;
- }
- function get Limits()
- {
- var _loc4_ = new Object();
- var _loc3_ = undefined;
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ <= this.aLayers.length - 1)
- {
- if(this.aLayers[_loc2_].Id == this.oDefaultLayerId)
- {
- _loc3_ = this.aLayers[_loc2_];
- }
- _loc2_ = _loc2_ + 1;
- }
- _loc4_.left = 0;
- _loc4_.right = _loc3_.PanelsWidth;
- _loc4_.top = 0;
- _loc4_.bottom = _loc3_.PanelsHeight;
- return _loc4_;
- }
- function doMoveLayers()
- {
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ <= this.aLayers.length - 1)
- {
- if(this.nScrollMethod == SideScroller.SideScrollerManager.SCROLL_ONE_WAY)
- {
- var _loc3_ = this.nCurrentPosition;
- this.nCurrentPosition = Math.min(this.nCurrentPosition,this.oCamera.PosX);
- if(this.nCurrentPosition < this.oCamera.PosX - SideScroller.SideScrollerManager.ONE_WAY_CAMERA_BUFFER)
- {
- this.nCurrentPosition = this.oCamera.PosX - SideScroller.SideScrollerManager.ONE_WAY_CAMERA_BUFFER;
- }
- else if(this.bAutoScroll)
- {
- this.nCurrentPosition -= this.nScrollSpeed;
- }
- if(this.nCurrentPosition < - (this.Limits.right - this.nStageWidth))
- {
- this.nCurrentPosition = - (this.Limits.right - this.nStageWidth);
- }
- if(this.nCurrentPosition > _loc3_)
- {
- this.nCurrentPosition = _loc3_;
- }
- }
- else
- {
- this.nCurrentPosition = this.oCamera.PosX;
- }
- this.aLayers[_loc2_].doMoveTo(this.nCurrentPosition,this.oCamera.PosY);
- _loc2_ = _loc2_ + 1;
- }
- }
- }
-